package designPatterns_demo.chain_of_responsibility_pattern.demo1;

public abstract class AbstractLogger {
    public static int INFO = 1;
    public static int DEBUG = 2;
    public static int ERROR = 3;

    protected int level;

    // 责任链中的下一个元素
    protected  AbstractLogger nextLogger;

    public AbstractLogger(int level) {
        this.level = level;
    }

    public void setNextLogger(AbstractLogger nextLogger) {
        this.nextLogger = nextLogger;
    }

    public void logMessage(int level, String message) {
        if (this.level == level) {
            this.write(message);
        } else {
            if (this.nextLogger != null) {
                nextLogger.write(message);
            } else {
                System.out.println("没有可处理请求的处理类！");
            }
        }
    }

    abstract protected void write(String message);
}
